package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.framework.core.utils.StringUtil;
import com.lzy.product.dao.ProductUserMapperExt;
import com.lzy.product.dtos.ProductUserDto;
import com.lzy.product.entity.ProductUser;
import com.lzy.product.service.ProductUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2017/11/28.
 */
@Service
public class ProductUserServiceImpl implements ProductUserService {

    @Autowired
    private ProductUserMapperExt productUserMapperExt;

    @Override
    public Long insert(ProductUserDto dto) {
        ProductUser user = DozerUtils.map(dto, ProductUser.class);
        return productUserMapperExt.insertSelective(user) > 0 ? user.getId() : 0;
    }

    @Override
    public Boolean update(ProductUserDto dto) {
        ProductUser user = DozerUtils.map(dto, ProductUser.class);
        return productUserMapperExt.updateByPrimaryKeySelective(user) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return productUserMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        return productUserMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public ProductUserDto findById(Long id) {
        return productUserMapperExt.findById(id);
    }

    @Override
    public List<ProductUserDto> query(ProductUserDto dto) {
        return productUserMapperExt.query(dto);
    }

    @Override
    public ProductUserDto findUserByCont(ProductUserDto userDto) {
        return productUserMapperExt.findUserByCont(userDto);
    }

    @Override
    public PageInfo<ProductUserDto> queryUserList(Pager pager, ProductUserDto user) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ProductUserDto> produceUserList = productUserMapperExt.query(user);
        return new PageInfo<>(produceUserList);
    }

    @Override
    public List<ProductUserDto> selectUserListByUserId(Long userId) {
        return productUserMapperExt.selectUserListByUserId(userId);
    }

    @Override
    public String maxiNumber(String expression) {
        return productUserMapperExt.maxiNumber(expression);
    }

    @Override
    public PageInfo<ProductUserDto> queryAgents(Pager pager, ProductUserDto user) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ProductUserDto> produceUserList = productUserMapperExt.queryAgents(user);
        return new PageInfo<>(produceUserList);
    }

    @Override
    public List<Integer> queryAllCitycode() {
        return productUserMapperExt.queryAllCitycode();
    }


    @Override
    public List<ProductUserDto> selectListById(Long id, Integer type) {
        return productUserMapperExt.selectListById(id, type);
    }

    @Override
    public ProductUserDto queryAgentByphone(String phone) {
        return productUserMapperExt.queryAgentByphone(phone);
    }
}
